#include "wl_utils.h"

#include "wl_malloc.h"
#include "wl_trace.h"

#include <string.h>
#include <unistd.h>
#include <ak_common.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

void wl_sleep(wl_uint32 seconds) {
    ak_sleep_ms(seconds * 1000);
}

void wl_msleep(wl_uint32 milliseconds) {
    ak_sleep_ms(milliseconds);
}

wl_time wl_utctime(void) {
    return (wl_time)time(wl_null);
}

wl_char* wl_strdup(const wl_char* s) {
    wl_size len = strlen(s) + 1;
    void* new = wl_malloc(len);

    if (new == wl_null)
        return wl_null;

    return (wl_char*)memcpy(new, s, len);
}

wl_uint32 wl_getElapsedTick(void) {
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
}

#ifdef WIN32
int strcasecmp(const char* pszStr1, const char* pszStr2) {
    return _stricmp(pszStr1, pszStr2);
}

int strncasecmp(const char* pszStr1, const char* pszStr2, int len) {
    return _strnicmp(pszStr1, pszStr2, (size_t)len);
}
#endif

#ifdef __cplusplus
}
#endif /* __cplusplus */
